package com.example.service;

import android.content.Context;
import android.net.Uri;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.callback.NavCallback;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.constants.Constants;
import com.example.interfaces.IService;

@Route(path = Constants.JUMP_TARGRT_ACTIVIT_UTL, name = "测试服务")
public class MyService implements IService {

    @Override
    public void sayHello(Context context) {
        Toast.makeText(  context , "hello", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void jumpActivity(final Context context, String activityUrl,String key,String value) {  //页面跳转
                 ARouter.getInstance()
                        .build(activityUrl)
                        .withString(key,value)
                        .navigation(context, new NavCallback() {
                            @Override
                            public void onFound(Postcard postcard) {
                                Toast.makeText(context,"zhao" +"onArrival: 找到了",Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onLost(Postcard postcard) {
                                Toast.makeText(context,"zhao" +"onArrival: 找不到了",Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onInterrupt(Postcard postcard) {
//                                EventBus.getDefault().post(new OpenDialogEvent());
//                                Toast.makeText(context,"zhao" +"onArrival: 被拦截了",Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onArrival(Postcard postcard) {
                                Toast.makeText(context,"zhao" +"onArrival:跳转完了",Toast.LENGTH_SHORT).show();
                            }
                        });
    }

    /**
     * 来自服务器的Url
     * @param context
     * @param uri
     */
    @Override
    public void jumpActivity2(final Context context, Uri uri) {
        ARouter.getInstance()
                .build(uri)
                .navigation(context, new NavCallback() {
                    @Override
                    public void onFound(Postcard postcard) {
                        Toast.makeText(context,"zhao" +"onArrival: 找到了",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onLost(Postcard postcard) {
                        Toast.makeText(context,"zhao" +"onArrival: 找不到了",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onInterrupt(Postcard postcard) {
                        Toast.makeText(context,"zhao" +"onArrival: 被拦截了",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onArrival(Postcard postcard) {
                        Toast.makeText(context,"zhao" +"onArrival:跳转完了",Toast.LENGTH_SHORT).show();
                    }
                });
    }

    @Override
    public void init(Context context) {

    }
}
